/*     */ package com.zimbra.cs.service.mail;
/*     */ 
/*     */ import com.zimbra.common.util.ByteUtil;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.service.FileUploadServlet.Upload;
/*     */ import java.io.IOException;
/*     */ import java.io.InputStream;
/*     */ import java.net.MalformedURLException;
/*     */ import java.util.Iterator;
/*     */ import java.util.LinkedList;
/*     */ import java.util.List;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public abstract class UploadScanner
/*     */ {
/*     */   public static final class Result
/*     */   {
/*     */     private String mDesc;
/*     */     
/*     */     Result(String desc)
/*     */     {
/*  37 */       this.mDesc = desc;
/*     */     }
/*     */     
/*     */     public String toString() {
/*  41 */       return this.mDesc;
/*     */     }
/*     */   }
/*     */   
/*  45 */   public static final Result ACCEPT = new Result("ACCEPT");
/*  46 */   public static final Result REJECT = new Result("REJECT");
/*  47 */   public static final Result ERROR = new Result("ERROR");
/*     */   
/*  49 */   private static List<UploadScanner> sRegisteredScanners = new LinkedList();
/*     */   
/*     */   public static void registerScanner(UploadScanner scanner) {
/*  52 */     sRegisteredScanners.add(scanner);
/*     */   }
/*     */   
/*     */   public static void unregisterScanner(UploadScanner scanner) {
/*  56 */     sRegisteredScanners.remove(scanner);
/*     */   }
/*     */   
/*     */   public static Result accept(FileUploadServlet.Upload up, StringBuffer info)
/*     */   {
/*  61 */     InputStream is = null;
/*     */     try {
/*  63 */       is = up.getInputStream();
/*     */     } catch (IOException ioe) {
/*  65 */       ZimbraLog.misc.error("exception getting input stream for scanning", ioe);
/*  66 */       info.append(" ").append(ioe);
/*  67 */       return ERROR;
/*     */     }
/*  69 */     for (Iterator iter = sRegisteredScanners.iterator(); iter.hasNext();) {
/*  70 */       UploadScanner scanner = (UploadScanner)iter.next();
/*  71 */       if (scanner.isEnabled())
/*     */       {
/*     */         Result result;
/*     */         
/*     */         try
/*     */         {
/*  77 */           result = scanner.accept(is, info);
/*     */         } finally {
/*  79 */           ByteUtil.closeStream(is);
/*     */         }
/*  81 */         if ((result == REJECT) || (result == ERROR))
/*     */         {
/*     */ 
/*     */ 
/*  85 */           return result; }
/*     */       }
/*     */     }
/*  88 */     return ACCEPT;
/*     */   }
/*     */   
/*     */   public static Result acceptStream(InputStream is, StringBuffer info)
/*     */   {
/*  93 */     for (Iterator iter = sRegisteredScanners.iterator(); iter.hasNext();)
/*     */     {
/*  95 */       UploadScanner scanner = (UploadScanner)iter.next();
/*  96 */       if (scanner.isEnabled())
/*     */       {
/*     */         Result result;
/*     */         
/*     */         try
/*     */         {
/* 102 */           result = scanner.accept(is, info);
/*     */         } finally {
/* 104 */           ByteUtil.closeStream(is);
/*     */         }
/* 106 */         if ((result == REJECT) || (result == ERROR))
/*     */         {
/*     */ 
/*     */ 
/* 110 */           return result; }
/*     */       }
/*     */     }
/* 113 */     return ACCEPT;
/*     */   }
/*     */   
/*     */   protected abstract Result accept(InputStream paramInputStream, StringBuffer paramStringBuffer);
/*     */   
/*     */   protected abstract Result accept(byte[] paramArrayOfByte, StringBuffer paramStringBuffer);
/*     */   
/*     */   public abstract void setURL(String paramString)
/*     */     throws MalformedURLException;
/*     */   
/*     */   public abstract boolean isEnabled();
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/mail/UploadScanner.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */